/*     */ package com.cr.api.controller;
/*     */ 
/*     */ import com.cr.api.model.AddSourceEntrustmentModel;
/*     */ import com.cr.api.vo.SourceEntrustmentVo;
/*     */ import com.cr.business.domain.CrEvidenceInfo;
/*     */ import com.cr.business.domain.CrSourceEntrustment;
/*     */ import com.cr.business.service.ICrEvidenceInfoService;
/*     */ import com.cr.business.service.ICrSourceEntrustmentService;
/*     */ import com.cr.common.core.controller.BaseController;
/*     */ import com.cr.common.core.domain.AjaxResult;
/*     */ import com.cr.common.utils.ConvertUtil;
/*     */ import com.cr.common.utils.MyDateUtils;
/*     */ import com.cr.common.utils.MyStringUtils;
/*     */ import com.github.pagehelper.PageInfo;
/*     */ import java.text.SimpleDateFormat;
import java.util.ArrayList;
/*     */ import java.util.Arrays;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import java.util.stream.Collectors;
/*     */ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.web.bind.annotation.*;
/*     */
/*     */
/*     */

/*     */
          @Api("案源委托")
/*     */ @RestController
/*     */ @RequestMapping({"/api/entrustment"})
          @CrossOrigin
/*     */ public class ApiSourceEntrustmentController extends BaseController {
/*     */   @Autowired
/*     */   private ICrSourceEntrustmentService crSourceEntrustmentService;
/*     */   
/*     */   @Autowired
/*     */   private ICrEvidenceInfoService evidenceInfoService;
/*     */   
/*     */   @PostMapping({"/releaseEntrustment"})
/*     */   @ResponseBody
            @ApiOperation("发布案源委托")
/*     */   public AjaxResult releaseEntrustment(@RequestBody AddSourceEntrustmentModel model) {
/*  48 */     if (model.getUserId() == null)
/*  49 */       return AjaxResult.error("用户id不能为空"); 
/*  51 */     CrSourceEntrustment crSourceEntrustment = new CrSourceEntrustment();
/*  52 */     BeanUtils.copyProperties(model, crSourceEntrustment);
/*  53 */     crSourceEntrustment.setCreateBy(model.getUserId().toString());
/*  54 */     crSourceEntrustment.setCreateTime(new Date());
    crSourceEntrustment.setManagementCode("AY"+new SimpleDateFormat("yyyyMMdd").format(new Date())+(int)((Math.random()*9+1)*1000));
/*  56 */     int i = this.crSourceEntrustmentService.insertCrSourceEntrustment(crSourceEntrustment);
///*  57 */     if (i > 0 &&
///*  58 */       MyStringUtils.isNotEmpty(model.getImage())) {
///*  59 */       List<String> imageList = Arrays.asList(model.getImage().split(","));
///*  60 */       for (String image : imageList) {
///*  61 */         CrEvidenceInfo info = new CrEvidenceInfo();
///*  62 */         info.setImage(image);
///*  63 */         info.setClueId(crSourceEntrustment.getEntrustId());
///*  64 */         info.setType(Integer.valueOf(2));
///*  65 */         info.setCreateTime(new Date());
///*  66 */         this.evidenceInfoService.insertCrEvidenceInfo(info);
///*     */       }
///*     */     }
/*  70 */     return toAjax(i);
/*     */   }
/*     */   
/**
 * 案源详情列表
 * @param time
 * @return
 */
            @ApiOperation("案源详情列表")
            @ApiImplicitParam(name = "time", value = "时间", dataType = "String")
            @PostMapping("/getEntrustmentList")
            @ResponseBody
            public AjaxResult getEntrustmentList(@RequestBody CrSourceEntrustment param){
            
                String time = param.getTime();
                String userId = param.getCreateBy();
                CrSourceEntrustment sourceEntrustment = new CrSourceEntrustment();
                if(MyStringUtils.isNotEmpty(time)){
                    sourceEntrustment.setCreateTime(MyDateUtils.dateTime( "yyyy-MM-dd", time));
                }
                sourceEntrustment.setApprovalStatus(1);
                if(MyStringUtils.isNotEmpty(userId)) {
                    sourceEntrustment.setCreateBy(userId);
                    sourceEntrustment.setApprovalStatus(null);
                }
                startPage();
                List<CrSourceEntrustment> sourceEntrustmentList = crSourceEntrustmentService.selectCrSourceEntrustmentList(sourceEntrustment);
                List<SourceEntrustmentVo> sourceEntrustmentVoList = new ArrayList<>();
                if(sourceEntrustmentList.size() > 0){
                    sourceEntrustmentVoList = ConvertUtil.convertList(sourceEntrustmentList, SourceEntrustmentVo.class);
                }
                return AjaxResult.success(new PageInfo<>(sourceEntrustmentVoList));
            }
/*     */   
/*     */   @PostMapping({"/getEntrustmentInfo"})
/*     */   @ResponseBody
            @ApiOperation("获取案源详情")
            @ApiImplicitParams({
                    @ApiImplicitParam(name="entrustId", required = true,value = "案源ID",dataType = "数值"),
            })
/*     */   public AjaxResult getEntrustmentInfo(@RequestBody CrSourceEntrustment param) {
              Long entrustId = param.getEntrustId();
/* 104 */     if (entrustId == null)
/* 105 */       return AjaxResult.error("案源ID不能为空"); 
/* 107 */     CrSourceEntrustment crSourceEntrustment = this.crSourceEntrustmentService.selectCrSourceEntrustmentByEntrustId(entrustId);
/* 108 */     SourceEntrustmentVo sourceEntrustmentVo = (SourceEntrustmentVo)ConvertUtil.convert(crSourceEntrustment, SourceEntrustmentVo.class);
///* 109 */     CrEvidenceInfo evidenceInfo = new CrEvidenceInfo();
///* 110 */     evidenceInfo.setClueId(entrustId);
///* 111 */     evidenceInfo.setType(Integer.valueOf(2));
///* 112 */     List<CrEvidenceInfo> infoList = this.evidenceInfoService.selectCrEvidenceInfoList(evidenceInfo);
///* 113 */     if (infoList.size() > 0) {
///* 114 */       List<String> imageList = (List<String>)infoList.stream().map(v -> v.getImage()).collect(Collectors.toList());
///* 115 */       sourceEntrustmentVo.setImageList(imageList);
///*     */     }
/* 117 */     return AjaxResult.success(sourceEntrustmentVo);
/*     */   }

/*     */   @PostMapping({"/updateEntrustment"})
/*     */   @ResponseBody
            @ApiOperation("编辑案源委托")
/*     */   public AjaxResult updateEntrustment(@RequestBody AddSourceEntrustmentModel model) {
/*  48 */     if (model.getEntrustId() == null)
/*  49 */       return AjaxResult.error("案源委托id不能为空"); 
/*  51 */     CrSourceEntrustment crSourceEntrustment = new CrSourceEntrustment();
/*  52 */     BeanUtils.copyProperties(model, crSourceEntrustment);
/*  53 */     crSourceEntrustment.setUpdateBy(model.getUserId().toString());
/*  54 */     crSourceEntrustment.setUpdateTime(new Date());
/*  55 */     crSourceEntrustment.setApprovalStatus(Integer.valueOf(0));
              //crSourceEntrustment.setManagementCode("AY"+new SimpleDateFormat("yyyyMMdd").format(new Date())+(int)((Math.random()*9+1)*1000));
/*  56 */     int i = this.crSourceEntrustmentService.updateCrSourceEntrustment(crSourceEntrustment);
///*  57 */     if (i > 0 &&
///*  58 */       MyStringUtils.isNotEmpty(model.getImage())) {
///*  59 */       List<String> imageList = Arrays.asList(model.getImage().split(","));
///*  60 */       for (String image : imageList) {
///*  61 */         CrEvidenceInfo info = new CrEvidenceInfo();
///*  62 */         info.setImage(image);
///*  63 */         info.setClueId(crSourceEntrustment.getEntrustId());
///*  64 */         info.setType(Integer.valueOf(2));
///*  65 */         info.setCreateTime(new Date());
//                  this.evidenceInfoService.deleteCrEvidenceInfoByClueId(crSourceEntrustment.getEntrustId());
///*  66 */         this.evidenceInfoService.insertCrEvidenceInfo(info);
///*     */       }
///*     */     }
/*  70 */     return toAjax(i);
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-api-4.7.0.jar!\com\cr\api\controller\ApiSourceEntrustmentController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */